#include "driver.h"

NTSTATUS
DDDetachDevice(IN PDEVICE_OBJECT device) {
	int i;

	for (i = 0; i < MAX_ATTACHED_DEVICES_COUNT; ++i){
		if (device == AttachedDevices[i])
		{
			PDD_DEVICE dext = device->DeviceExtension;
			AttachedDevices[i] = NULL;
			if (KeGetCurrentIrql() == PASSIVE_LEVEL){
				DbgMess(("Detach device 0x%x", device));
				IoDetachDevice(dext->FileSystem);
				IoDeleteDevice(device);
			} else {
				DbgMess(("Cannot detach device 0x%x, because of IRQ Level", device));
				return STATUS_INVALID_LEVEL;
			}
			break;
		}
	}
	return STATUS_SUCCESS;
}